package com.java.utils;

/**
* @ClassName: UserSession
* @Description: 记录用户登陆信息
* @author ChenJiaLu
* @date 2023年12月29日 上午9:55:18
*
 */
public class UserSession {
	
	private static UserSession instance = new UserSession();

	private UserSession() {}

	private Integer userId;
	
	private String userName;
	
	private String userPassword;
	
	/**
	 * 1管理员，2医生，3患者
	 */
	private int userRole = 0;
  
    public static UserSession getInstance() {  
        return instance;  
    }
    /**
     * 预设/更改登陆信息
     */
	public void setVal(int userId, String userName, String userPassword, int userRole) {
		this.userId = userId;
		this.userName = userName;
		this.userPassword = userPassword;
		this.userRole = userRole;
	}
	/**
	 * 是否登陆
	 */
	public boolean isLogin() {
		if(null == userId) {
			return false;
		}
		return true;
	}
	/**
	 * 退出登陆
	 */
	public void logout() {
		this.userId = null;
		this.userName = null;
	}
	/**
	 * 是否管理员角色
	 */
	public boolean isAdmin() {
		return userRole == 1;
	}
	/**
	 * 是否医生
	 */
	public boolean isDoctor() {
		return userRole == 2;
	}
	/**
	 * 是否患者
	 */
	public boolean isPatient() {
		return userRole == 3;
	}
	
	/**
	 * 常规get&set
	 */
	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public int getUserRole() {
		return userRole;
	}

	public void setUserRole(int userRole) {
		this.userRole = userRole;
	}

	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}
	
}
